/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OrderManage.java
 *
 * Created on 2009-12-6, 15:08:38
 */
package com.ordering.menu;

import com.ordering.login.Login;
import com.ordering.pojo.UserManage;
import com.ordering.utils.WindowLocationUtils;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 *
 * @author hua
 */
public class OrderManage extends javax.swing.JFrame implements Runnable {
    private UserManage um;

    public UserManage getUm() {
        return um;
    }

    /** Creates new form OrderManage */
    public OrderManage(UserManage um) {
        initComponents();
        this.um = um;
        String isManager = um.getUserType().toString();
        if (isManager == null || !isManager.trim().equals("1"))
        {
            btnManageMenu.setVisible(false);
            btnCustomer.setVisible(false);
            btnUser.setVisible(false);
            btnOrder.setVisible(false);
        }
        WindowLocationUtils.setWindowCenter(this);
        Thread th = new Thread(this);
        th.start(); //开始线程
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnInOrder = new javax.swing.JButton();
        btnOutOrder = new javax.swing.JButton();
        btnPhoneOrder = new javax.swing.JButton();
        btnUser = new javax.swing.JButton();
        btnCustomer = new javax.swing.JButton();
        timer = new javax.swing.JLabel();
        btnManageMenu = new javax.swing.JButton();
        btnOrder = new javax.swing.JButton();
        btnUpdatePwd = new javax.swing.JButton();
        btnReLogin = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnInOrder.setText("餐厅就餐");
        btnInOrder.setName("btnInOrder"); // NOI18N
        btnInOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInOrderActionPerformed(evt);
            }
        });

        btnOutOrder.setText("打包外卖");
        btnOutOrder.setName("btnOutOrder"); // NOI18N
        btnOutOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOutOrderActionPerformed(evt);
            }
        });

        btnPhoneOrder.setText("电话订餐");
        btnPhoneOrder.setName("btnPhoneOrder"); // NOI18N
        btnPhoneOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPhoneOrderActionPerformed(evt);
            }
        });

        btnUser.setText("用户管理");
        btnUser.setName("btnUser"); // NOI18N
        btnUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUserActionPerformed(evt);
            }
        });

        btnCustomer.setText("会员管理");
        btnCustomer.setName("btnCustomer"); // NOI18N
        btnCustomer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCustomerActionPerformed(evt);
            }
        });

        timer.setFont(new java.awt.Font("黑体", 1, 18));
        timer.setForeground(new java.awt.Color(102, 102, 255));
        timer.setName("timer"); // NOI18N
        timer.setText(this.getTimeInfo());

        btnManageMenu.setText("菜谱维护");
        btnManageMenu.setName("btnManageMenu"); // NOI18N
        btnManageMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnManageMenuActionPerformed(evt);
            }
        });

        btnOrder.setText("订单管理");
        btnOrder.setName("btnOrder"); // NOI18N
        btnOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOrderActionPerformed(evt);
            }
        });

        btnUpdatePwd.setText("修改密码");
        btnUpdatePwd.setName("btnUpdatePwd"); // NOI18N
        btnUpdatePwd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUpdatePwdActionPerformed(evt);
            }
        });

        btnReLogin.setText("重新登录");
        btnReLogin.setName("btnReLogin"); // NOI18N
        btnReLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReLoginActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnReLogin)
                        .addGap(18, 18, 18)
                        .addComponent(timer, javax.swing.GroupLayout.PREFERRED_SIZE, 413, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(btnInOrder, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnOrder)
                        .addComponent(btnUpdatePwd, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnPhoneOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnOutOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnUser)
                        .addComponent(btnCustomer)
                        .addComponent(btnManageMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(57, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCustomer, btnInOrder, btnManageMenu, btnOrder, btnOutOrder, btnPhoneOrder, btnReLogin, btnUpdatePwd, btnUser});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnReLogin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnInOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnOutOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addComponent(btnPhoneOrder)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnUpdatePwd)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnOrder)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCustomer, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnUser, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnManageMenu))
                    .addComponent(timer, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnCustomer, btnInOrder, btnManageMenu, btnOrder, btnOutOrder, btnPhoneOrder, btnReLogin, btnUpdatePwd, btnUser});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCustomerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCustomerActionPerformed
        VipManageList listUI = new VipManageList(this, false);
        listUI.setVisible(true);
    }//GEN-LAST:event_btnCustomerActionPerformed

    private void btnUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUserActionPerformed
        UserManageList listUI = new UserManageList(this, false);
        listUI.setVisible(true);
    }//GEN-LAST:event_btnUserActionPerformed

    private void btnInOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInOrderActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                final CreateOrderDialog dialog = new CreateOrderDialog(OrderManage.this, false);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        dialog.dispose();
                    }
                });
                dialog.setVisible(true);
            }
        });
    }//GEN-LAST:event_btnInOrderActionPerformed

    private void btnOutOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOutOrderActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                final CreateOrderDialog dialog = new CreateOrderDialog(OrderManage.this, false);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        dialog.dispose();
                    }
                });
                dialog.setVisible(true);
            }
        });
    }//GEN-LAST:event_btnOutOrderActionPerformed

    private void btnPhoneOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPhoneOrderActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                final CreateOrderDialog dialog = new CreateOrderDialog(OrderManage.this, false);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        dialog.dispose();
                    }
                });
                dialog.setVisible(true);
            }
        });
    }//GEN-LAST:event_btnPhoneOrderActionPerformed

    private void btnManageMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnManageMenuActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                final ManageMenuDialog dialog = new ManageMenuDialog(OrderManage.this, false);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        dialog.dispose();
                    }
                });
                dialog.setVisible(true);
            }
        });
    }//GEN-LAST:event_btnManageMenuActionPerformed

    private void btnUpdatePwdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdatePwdActionPerformed
        UserPwdupdate updateWin = new UserPwdupdate(this,false);
        updateWin.setUserId(this.um.getPk());
        updateWin.setVisible(true);
    }//GEN-LAST:event_btnUpdatePwdActionPerformed

    private void btnOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOrderActionPerformed
        OrderList listWin = new OrderList(this,false);
        listWin.setUser(um);
        listWin.setVisible(true);
    }//GEN-LAST:event_btnOrderActionPerformed

    private void btnReLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReLoginActionPerformed
          Login login = new Login();
          login.setVisible(true);
          this.dispose();
    }//GEN-LAST:event_btnReLoginActionPerformed
    public void run() {  //运行线程
        while (true) {
            timer.setText(this.getTimeInfo());
//                timer.repaint(); //调用paint方法重绘界面
            try {
                Thread.sleep(1000);  //线程暂停一秒(1000毫秒)
                } catch (InterruptedException ex) {
                ex.printStackTrace();  //输出出错信息
                }
        }
    }

    public String getTimeInfo() {
        Calendar now = new GregorianCalendar(); //实例化日历对象
        String timeInfo = "公元 "; //输出信息
        int year = now.get(Calendar.YEAR);//得到年份
        int month = now.get(Calendar.MONTH);//得到月份
        int day = now.get(Calendar.DATE);//得到天
        int hour = now.get(Calendar.HOUR_OF_DAY); //得到小时数
        int minute = now.get(Calendar.MINUTE);   //得到分数
        int second = now.get(Calendar.SECOND);  //得到秒数
        int weekDay = now.get(Calendar.DAY_OF_WEEK);//得到星期数
        timeInfo += year + "-";
        if (month <= 9) {
            timeInfo += "0" + month + "-";
        } else {
            timeInfo += month + "-";
        }
        if (day <= 9) {
            timeInfo += "0" + day + "  ";
        } else {
            timeInfo += day + "  ";
        }
        if (hour <= 9) {
            timeInfo += "0" + hour + ":"; //格式化输出
        } else {
            timeInfo += hour + ":";
        }
        if (minute <= 9) {
            timeInfo += "0" + minute + ":";
        } else {
            timeInfo += minute + ":";
        }
        if (second <= 9) {
            timeInfo += "0" + second + "  ";
        } else {
            timeInfo += second + "  ";
        }
        timeInfo += "星期";
        switch (weekDay) {
            case 1:
                timeInfo += "日";
                break;
            case 2:
                timeInfo += "一";
                break;
            case 3:
                timeInfo += "二";
                break;
            case 4:
                timeInfo += "三";
                break;
            case 5:
                timeInfo += "四";
                break;
            case 6:
                timeInfo += "五";
                break;
            case 7:
                timeInfo += "六";
                break;
        }
        return timeInfo;
    }

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                new OrderManage().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCustomer;
    private javax.swing.JButton btnInOrder;
    private javax.swing.JButton btnManageMenu;
    private javax.swing.JButton btnOrder;
    private javax.swing.JButton btnOutOrder;
    private javax.swing.JButton btnPhoneOrder;
    private javax.swing.JButton btnReLogin;
    private javax.swing.JButton btnUpdatePwd;
    private javax.swing.JButton btnUser;
    private javax.swing.JLabel timer;
    // End of variables declaration//GEN-END:variables
}
